#!/usr/bin/env python
"""
Prints 10 longest lasting tests from JSON PHPUnit log
"""

from __future__ import print_function

import json
import sys

def main(filename):
    with open(filename) as handle:
        content = handle.read()
    data = json.loads(
        '[' + content.replace('}{', '},{') + ']'
    )
    printed = ['test', 'status', 'time']
    tests = [item for item in data if item['event'] == 'test']
    for test in sorted(tests, key=lambda item: -item['time'])[:10]:
        for item in printed:
            print('{0:10s}: {1}'.format(item, test[item]))
        print()


if __name__ == '__main__':
    main(*sys.argv[1:])
